<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>libcoap: mem.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">libcoap<span id="projectnumber">&#160;4.2.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.8 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function() { init_codefold(0); });
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('mem_8c_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div class="header">
  <div class="headertitle"><div class="title">mem.c</div></div>
</div><!--header-->
<div class="contents">
<a href="mem_8c.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span><span class="comment">/* mem.c -- CoAP memory handling</span></div>
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno">    2</span><span class="comment"> *</span></div>
<div class="line"><a id="l00003" name="l00003"></a><span class="lineno">    3</span><span class="comment"> * Copyright (C) 2014--2015 Olaf Bergmann &lt;bergmann@tzi.org&gt;</span></div>
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno">    4</span><span class="comment"> *</span></div>
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno">    5</span><span class="comment"> * This file is part of the CoAP library libcoap. Please see</span></div>
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno">    6</span><span class="comment"> * README for terms of use.</span></div>
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno">    7</span><span class="comment"> */</span></div>
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno">    8</span> </div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno">    9</span> </div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno">   10</span><span class="preprocessor">#include &quot;coap_config.h&quot;</span></div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno">   11</span><span class="preprocessor">#include &quot;<a class="code" href="libcoap_8h.html">libcoap.h</a>&quot;</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno">   12</span><span class="preprocessor">#include &quot;<a class="code" href="mem_8h.html">mem.h</a>&quot;</span></div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno">   13</span><span class="preprocessor">#include &quot;<a class="code" href="coap__debug_8h.html">coap_debug.h</a>&quot;</span></div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno">   14</span> </div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno">   15</span><span class="preprocessor">#ifdef HAVE_ASSERT_H</span></div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno">   16</span><span class="preprocessor">#include &lt;assert.h&gt;</span></div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno">   17</span><span class="preprocessor">#else </span><span class="comment">/* HAVE_ASSERT_H */</span><span class="preprocessor"></span></div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno"><a class="line" href="mem_8c.html#a3d4ae9c092e117c836f52dc7d7cee574">   18</a></span><span class="preprocessor">#define assert(...)</span></div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno">   19</span><span class="preprocessor">#endif </span><span class="comment">/* HAVE_ASSERT_H */</span><span class="preprocessor"></span></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno">   20</span> </div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno">   21</span><span class="preprocessor">#ifdef HAVE_MALLOC</span></div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno">   22</span><span class="preprocessor">#include &lt;stdlib.h&gt;</span></div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno">   23</span> </div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno">   24</span><span class="keywordtype">void</span></div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno">   25</span><a class="code hl_function" href="mem_8h.html#a65d0fc0fe6cad555b56e92ccb57613ba">coap_memory_init</a>(<span class="keywordtype">void</span>) {</div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno">   26</span>}</div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno">   27</span> </div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno">   28</span><span class="preprocessor">#ifdef __GNUC__</span></div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno">   29</span><span class="preprocessor">#define UNUSED_PARAM __attribute__((unused))</span></div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno">   30</span><span class="preprocessor">#else</span></div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno">   31</span><span class="preprocessor">#define UNUSED_PARAM</span></div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno">   32</span><span class="preprocessor">#endif </span><span class="comment">/* __GNUC__ */</span><span class="preprocessor"></span></div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno">   33</span> </div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno">   34</span><span class="keywordtype">void</span> *</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno">   35</span><a class="code hl_function" href="mem_8h.html#a9f9fd8d6cf24f9c45a5501aeba5acaf9">coap_malloc_type</a>(<a class="code hl_enumeration" href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620">coap_memory_tag_t</a> type, <span class="keywordtype">size_t</span> size) {</div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno">   36</span>  (void)type;</div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno">   37</span>  <span class="keywordflow">return</span> malloc(size);</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno">   38</span>}</div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno">   39</span> </div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno">   40</span><span class="keywordtype">void</span></div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno">   41</span><a class="code hl_function" href="mem_8h.html#ae7214e0c73a4d4290525873e739ed422">coap_free_type</a>(<a class="code hl_enumeration" href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620">coap_memory_tag_t</a> type, <span class="keywordtype">void</span> *p) {</div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno">   42</span>  (void)type;</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span>  free(p);</div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno">   44</span>}</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno">   45</span> </div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span><span class="preprocessor">#else </span><span class="comment">/* HAVE_MALLOC */</span><span class="preprocessor"></span></div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno">   47</span> </div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno">   48</span><span class="preprocessor">#ifdef WITH_CONTIKI</span></div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno">   49</span> </div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno">   54</span><span class="preprocessor">#ifndef COAP_MAX_STRING_SIZE</span></div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno">   55</span><span class="preprocessor">#define COAP_MAX_STRING_SIZE 64</span></div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno">   56</span><span class="preprocessor">#endif </span><span class="comment">/* COAP_MAX_STRING_SIZE */</span><span class="preprocessor"></span></div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno">   57</span> </div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno">   62</span><span class="preprocessor">#ifndef COAP_MAX_STRINGS</span></div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno">   63</span><span class="preprocessor">#define COAP_MAX_STRINGS      10</span></div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno">   64</span><span class="preprocessor">#endif </span><span class="comment">/* COAP_MAX_STRINGS */</span><span class="preprocessor"></span></div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno">   65</span> </div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno">   66</span><span class="keyword">struct </span>coap_stringbuf_t {</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno">   67</span>  <span class="keywordtype">char</span> data[COAP_MAX_STRING_SIZE];</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno">   68</span>};</div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno">   69</span> </div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno">   70</span><span class="preprocessor">#include &quot;coap_config.h&quot;</span></div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno">   71</span><span class="preprocessor">#include &quot;<a class="code" href="net_8h.html">net.h</a>&quot;</span></div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno">   72</span><span class="preprocessor">#include &quot;<a class="code" href="pdu_8h.html">pdu.h</a>&quot;</span></div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno">   73</span><span class="preprocessor">#include &quot;<a class="code" href="coap__io_8h.html">coap_io.h</a>&quot;</span></div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno">   74</span><span class="preprocessor">#include &quot;<a class="code" href="resource_8h.html">resource.h</a>&quot;</span></div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno">   75</span><span class="preprocessor">#include &quot;<a class="code" href="coap__session_8h.html">coap_session.h</a>&quot;</span></div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span> </div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno">   77</span><span class="preprocessor">#define COAP_MAX_PACKET_SIZE (sizeof(coap_packet_t) + COAP_RXBUFFER_SIZE)</span></div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno">   78</span><span class="preprocessor">#ifndef COAP_MAX_PACKETS</span></div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno">   79</span><span class="preprocessor">#define COAP_MAX_PACKETS     2</span></div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno">   80</span><span class="preprocessor">#endif </span><span class="comment">/* COAP_MAX_PACKETS */</span><span class="preprocessor"></span></div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno">   81</span> </div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno">   82</span><span class="keyword">typedef</span> <span class="keyword">union </span>{</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno">   83</span>  <a class="code hl_struct" href="structcoap__pdu__t.html">coap_pdu_t</a> packet; <span class="comment">/* try to convince the compiler to word-align this structure  */</span></div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno">   84</span>  <span class="keywordtype">char</span> buf[COAP_MAX_PACKET_SIZE];</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno">   85</span>} coap_packetbuf_t;</div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno">   86</span> </div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno">   87</span>MEMB(string_storage, <span class="keyword">struct</span> coap_stringbuf_t, COAP_MAX_STRINGS);</div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno">   88</span>MEMB(packet_storage, coap_packetbuf_t, COAP_MAX_PACKETS);</div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno">   89</span>MEMB(session_storage, <a class="code hl_struct" href="structcoap__session__t.html">coap_session_t</a>, COAP_MAX_SESSIONS);</div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno">   90</span>MEMB(node_storage, <a class="code hl_struct" href="structcoap__queue__t.html">coap_queue_t</a>, COAP_PDU_MAXCNT);</div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno">   91</span>MEMB(pdu_storage, <a class="code hl_struct" href="structcoap__pdu__t.html">coap_pdu_t</a>, COAP_PDU_MAXCNT);</div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno">   92</span>MEMB(pdu_buf_storage, coap_packetbuf_t, COAP_PDU_MAXCNT);</div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno">   93</span>MEMB(resource_storage, <a class="code hl_struct" href="structcoap__resource__t.html">coap_resource_t</a>, COAP_MAX_RESOURCES);</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno">   94</span>MEMB(attribute_storage, <a class="code hl_struct" href="structcoap__attr__t.html">coap_attr_t</a>, COAP_MAX_ATTRIBUTES);</div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno">   95</span> </div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno">   96</span><span class="keyword">static</span> <span class="keyword">struct </span>memb *</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno">   97</span>get_container(<a class="code hl_enumeration" href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620">coap_memory_tag_t</a> type) {</div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno">   98</span>  <span class="keywordflow">switch</span>(type) {</div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno">   99</span>  <span class="keywordflow">case</span> <a class="code hl_enumvalue" href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620ab4e8cb3171f267b830d97626ad7a8d69">COAP_PACKET</a>: <span class="keywordflow">return</span> &amp;packet_storage;</div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno">  100</span>  <span class="keywordflow">case</span> <a class="code hl_enumvalue" href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620a239e408c064f87c6e7cfa8b2d6442f9d">COAP_NODE</a>:   <span class="keywordflow">return</span> &amp;node_storage;</div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno">  101</span>  <span class="keywordflow">case</span> <a class="code hl_enumvalue" href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620a010f82674bff4f905896c7ff94252ce4">COAP_SESSION</a>: <span class="keywordflow">return</span> &amp;session_storage;</div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno">  102</span>  <span class="keywordflow">case</span> <a class="code hl_enumvalue" href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620a7442ae365f092f7aa0e516e6d67e7740">COAP_PDU</a>:     <span class="keywordflow">return</span> &amp;pdu_storage;</div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno">  103</span>  <span class="keywordflow">case</span> <a class="code hl_enumvalue" href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620ac7bb2f8183a3ed5a92a3e085b542f42f">COAP_PDU_BUF</a>: <span class="keywordflow">return</span> &amp;pdu_buf_storage;</div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno">  104</span>  <span class="keywordflow">case</span> <a class="code hl_enumvalue" href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620a3ed13177a838b75eb0c46d4f4dce85ac">COAP_RESOURCE</a>: <span class="keywordflow">return</span> &amp;resource_storage;</div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno">  105</span>  <span class="keywordflow">case</span> <a class="code hl_enumvalue" href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620a3ed3c7e549d893f00509f9e2f07249c0">COAP_RESOURCEATTR</a>: <span class="keywordflow">return</span> &amp;attribute_storage;</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno">  106</span>  <span class="keywordflow">default</span>:</div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno">  107</span>    <span class="keywordflow">return</span> &amp;string_storage;</div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno">  108</span>  }</div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno">  109</span>}</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno">  110</span> </div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno">  111</span><span class="keywordtype">void</span></div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno">  112</span><a class="code hl_function" href="mem_8h.html#a65d0fc0fe6cad555b56e92ccb57613ba">coap_memory_init</a>(<span class="keywordtype">void</span>) {</div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno">  113</span>  memb_init(&amp;string_storage);</div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno">  114</span>  memb_init(&amp;packet_storage);</div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno">  115</span>  memb_init(&amp;node_storage);</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno">  116</span>  memb_init(&amp;session_storage);</div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno">  117</span>  memb_init(&amp;pdu_storage);</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno">  118</span>  memb_init(&amp;pdu_buf_storage);</div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno">  119</span>  memb_init(&amp;resource_storage);</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno">  120</span>  memb_init(&amp;attribute_storage);</div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno">  121</span>}</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno">  122</span> </div>
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno">  123</span><span class="keywordtype">void</span> *</div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno">  124</span><a class="code hl_function" href="mem_8h.html#a9f9fd8d6cf24f9c45a5501aeba5acaf9">coap_malloc_type</a>(<a class="code hl_enumeration" href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620">coap_memory_tag_t</a> type, <span class="keywordtype">size_t</span> size) {</div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno">  125</span>  <span class="keyword">struct </span>memb *container =  get_container(type);</div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno">  126</span>  <span class="keywordtype">void</span> *ptr;</div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno">  127</span> </div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno">  128</span>  <a class="code hl_define" href="mem_8c.html#a3d4ae9c092e117c836f52dc7d7cee574">assert</a>(container);</div>
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno">  129</span> </div>
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno">  130</span>  <span class="keywordflow">if</span> (size &gt; container-&gt;size) {</div>
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno">  131</span>    <a class="code hl_define" href="group__logging.html#gaff2785484e756c8ec2fce408f9b81f0f">coap_log</a>(<a class="code hl_enumvalue" href="group__logging.html#gga53c7b97a7af4d62d8c1678d658cc7446a8f6fe15bfe15104da6d1b360194a5400">LOG_WARNING</a>,</div>
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno">  132</span>             <span class="stringliteral">&quot;coap_malloc_type: Requested memory exceeds maximum object &quot;</span></div>
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno">  133</span>             <span class="stringliteral">&quot;size (type %d, size %d, max %d)\n&quot;</span>,</div>
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno">  134</span>             type, (<span class="keywordtype">int</span>)size, container-&gt;size);</div>
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno">  135</span>    <span class="keywordflow">return</span> NULL;</div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno">  136</span>  }</div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno">  137</span> </div>
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno">  138</span>  ptr = memb_alloc(container);</div>
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno">  139</span>  <span class="keywordflow">if</span> (!ptr)</div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno">  140</span>    <a class="code hl_define" href="group__logging.html#gaff2785484e756c8ec2fce408f9b81f0f">coap_log</a>(<a class="code hl_enumvalue" href="group__logging.html#gga53c7b97a7af4d62d8c1678d658cc7446a8f6fe15bfe15104da6d1b360194a5400">LOG_WARNING</a>,</div>
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno">  141</span>             <span class="stringliteral">&quot;coap_malloc_type: Failure (no free blocks) for type %d\n&quot;</span>,</div>
<div class="line"><a id="l00142" name="l00142"></a><span class="lineno">  142</span>             type);</div>
<div class="line"><a id="l00143" name="l00143"></a><span class="lineno">  143</span>  <span class="keywordflow">return</span> ptr;</div>
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno">  144</span>}</div>
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno">  145</span> </div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno">  146</span><span class="keywordtype">void</span></div>
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno">  147</span><a class="code hl_function" href="mem_8h.html#ae7214e0c73a4d4290525873e739ed422">coap_free_type</a>(<a class="code hl_enumeration" href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620">coap_memory_tag_t</a> type, <span class="keywordtype">void</span> *<span class="keywordtype">object</span>) {</div>
<div class="line"><a id="l00148" name="l00148"></a><span class="lineno">  148</span>  memb_free(get_container(type), <span class="keywordtype">object</span>);</div>
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno">  149</span>}</div>
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno">  150</span><span class="preprocessor">#endif </span><span class="comment">/* WITH_CONTIKI */</span><span class="preprocessor"></span></div>
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno">  151</span> </div>
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno">  152</span><span class="preprocessor">#endif </span><span class="comment">/* HAVE_MALLOC */</span><span class="preprocessor"></span></div>
<div class="ttc" id="acoap__debug_8h_html"><div class="ttname"><a href="coap__debug_8h.html">coap_debug.h</a></div></div>
<div class="ttc" id="acoap__io_8h_html"><div class="ttname"><a href="coap__io_8h.html">coap_io.h</a></div></div>
<div class="ttc" id="acoap__session_8h_html"><div class="ttname"><a href="coap__session_8h.html">coap_session.h</a></div></div>
<div class="ttc" id="agroup__logging_html_gaff2785484e756c8ec2fce408f9b81f0f"><div class="ttname"><a href="group__logging.html#gaff2785484e756c8ec2fce408f9b81f0f">coap_log</a></div><div class="ttdeci">#define coap_log(level,...)</div><div class="ttdoc">Logging function.</div><div class="ttdef"><b>Definition</b> <a href="coap__debug_8h_source.html#l00122">coap_debug.h:122</a></div></div>
<div class="ttc" id="agroup__logging_html_gga53c7b97a7af4d62d8c1678d658cc7446a8f6fe15bfe15104da6d1b360194a5400"><div class="ttname"><a href="group__logging.html#gga53c7b97a7af4d62d8c1678d658cc7446a8f6fe15bfe15104da6d1b360194a5400">LOG_WARNING</a></div><div class="ttdeci">@ LOG_WARNING</div><div class="ttdoc">Warning.</div><div class="ttdef"><b>Definition</b> <a href="coap__debug_8h_source.html#l00046">coap_debug.h:46</a></div></div>
<div class="ttc" id="alibcoap_8h_html"><div class="ttname"><a href="libcoap_8h.html">libcoap.h</a></div></div>
<div class="ttc" id="amem_8c_html_a3d4ae9c092e117c836f52dc7d7cee574"><div class="ttname"><a href="mem_8c.html#a3d4ae9c092e117c836f52dc7d7cee574">assert</a></div><div class="ttdeci">#define assert(...)</div><div class="ttdef"><b>Definition</b> <a href="mem_8c_source.html#l00018">mem.c:18</a></div></div>
<div class="ttc" id="amem_8h_html"><div class="ttname"><a href="mem_8h.html">mem.h</a></div></div>
<div class="ttc" id="amem_8h_html_a65d0fc0fe6cad555b56e92ccb57613ba"><div class="ttname"><a href="mem_8h.html#a65d0fc0fe6cad555b56e92ccb57613ba">coap_memory_init</a></div><div class="ttdeci">void coap_memory_init(void)</div><div class="ttdoc">Initializes libcoap's memory management.</div></div>
<div class="ttc" id="amem_8h_html_a703fa791ab7a14ff983df73b15e9c620"><div class="ttname"><a href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620">coap_memory_tag_t</a></div><div class="ttdeci">coap_memory_tag_t</div><div class="ttdoc">Type specifiers for coap_malloc_type().</div><div class="ttdef"><b>Definition</b> <a href="mem_8h_source.html#l00029">mem.h:29</a></div></div>
<div class="ttc" id="amem_8h_html_a703fa791ab7a14ff983df73b15e9c620a010f82674bff4f905896c7ff94252ce4"><div class="ttname"><a href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620a010f82674bff4f905896c7ff94252ce4">COAP_SESSION</a></div><div class="ttdeci">@ COAP_SESSION</div><div class="ttdef"><b>Definition</b> <a href="mem_8h_source.html#l00044">mem.h:44</a></div></div>
<div class="ttc" id="amem_8h_html_a703fa791ab7a14ff983df73b15e9c620a239e408c064f87c6e7cfa8b2d6442f9d"><div class="ttname"><a href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620a239e408c064f87c6e7cfa8b2d6442f9d">COAP_NODE</a></div><div class="ttdeci">@ COAP_NODE</div><div class="ttdef"><b>Definition</b> <a href="mem_8h_source.html#l00034">mem.h:34</a></div></div>
<div class="ttc" id="amem_8h_html_a703fa791ab7a14ff983df73b15e9c620a3ed13177a838b75eb0c46d4f4dce85ac"><div class="ttname"><a href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620a3ed13177a838b75eb0c46d4f4dce85ac">COAP_RESOURCE</a></div><div class="ttdeci">@ COAP_RESOURCE</div><div class="ttdef"><b>Definition</b> <a href="mem_8h_source.html#l00039">mem.h:39</a></div></div>
<div class="ttc" id="amem_8h_html_a703fa791ab7a14ff983df73b15e9c620a3ed3c7e549d893f00509f9e2f07249c0"><div class="ttname"><a href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620a3ed3c7e549d893f00509f9e2f07249c0">COAP_RESOURCEATTR</a></div><div class="ttdeci">@ COAP_RESOURCEATTR</div><div class="ttdef"><b>Definition</b> <a href="mem_8h_source.html#l00040">mem.h:40</a></div></div>
<div class="ttc" id="amem_8h_html_a703fa791ab7a14ff983df73b15e9c620a7442ae365f092f7aa0e516e6d67e7740"><div class="ttname"><a href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620a7442ae365f092f7aa0e516e6d67e7740">COAP_PDU</a></div><div class="ttdeci">@ COAP_PDU</div><div class="ttdef"><b>Definition</b> <a href="mem_8h_source.html#l00037">mem.h:37</a></div></div>
<div class="ttc" id="amem_8h_html_a703fa791ab7a14ff983df73b15e9c620ab4e8cb3171f267b830d97626ad7a8d69"><div class="ttname"><a href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620ab4e8cb3171f267b830d97626ad7a8d69">COAP_PACKET</a></div><div class="ttdeci">@ COAP_PACKET</div><div class="ttdef"><b>Definition</b> <a href="mem_8h_source.html#l00033">mem.h:33</a></div></div>
<div class="ttc" id="amem_8h_html_a703fa791ab7a14ff983df73b15e9c620ac7bb2f8183a3ed5a92a3e085b542f42f"><div class="ttname"><a href="mem_8h.html#a703fa791ab7a14ff983df73b15e9c620ac7bb2f8183a3ed5a92a3e085b542f42f">COAP_PDU_BUF</a></div><div class="ttdeci">@ COAP_PDU_BUF</div><div class="ttdef"><b>Definition</b> <a href="mem_8h_source.html#l00038">mem.h:38</a></div></div>
<div class="ttc" id="amem_8h_html_a9f9fd8d6cf24f9c45a5501aeba5acaf9"><div class="ttname"><a href="mem_8h.html#a9f9fd8d6cf24f9c45a5501aeba5acaf9">coap_malloc_type</a></div><div class="ttdeci">void * coap_malloc_type(coap_memory_tag_t type, size_t size)</div><div class="ttdoc">Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.</div></div>
<div class="ttc" id="amem_8h_html_ae7214e0c73a4d4290525873e739ed422"><div class="ttname"><a href="mem_8h.html#ae7214e0c73a4d4290525873e739ed422">coap_free_type</a></div><div class="ttdeci">void coap_free_type(coap_memory_tag_t type, void *p)</div><div class="ttdoc">Releases the memory that was allocated by coap_malloc_type().</div></div>
<div class="ttc" id="anet_8h_html"><div class="ttname"><a href="net_8h.html">net.h</a></div></div>
<div class="ttc" id="apdu_8h_html"><div class="ttname"><a href="pdu_8h.html">pdu.h</a></div><div class="ttdoc">Pre-defined constants that reflect defaults for CoAP.</div></div>
<div class="ttc" id="aresource_8h_html"><div class="ttname"><a href="resource_8h.html">resource.h</a></div><div class="ttdoc">Generic resource handling.</div></div>
<div class="ttc" id="astructcoap__attr__t_html"><div class="ttname"><a href="structcoap__attr__t.html">coap_attr_t</a></div><div class="ttdef"><b>Definition</b> <a href="resource_8h_source.html#l00047">resource.h:47</a></div></div>
<div class="ttc" id="astructcoap__pdu__t_html"><div class="ttname"><a href="structcoap__pdu__t.html">coap_pdu_t</a></div><div class="ttdoc">structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...</div><div class="ttdef"><b>Definition</b> <a href="pdu_8h_source.html#l00285">pdu.h:285</a></div></div>
<div class="ttc" id="astructcoap__queue__t_html"><div class="ttname"><a href="structcoap__queue__t.html">coap_queue_t</a></div><div class="ttdoc">Queue entry.</div><div class="ttdef"><b>Definition</b> <a href="net_8h_source.html#l00039">net.h:39</a></div></div>
<div class="ttc" id="astructcoap__resource__t_html"><div class="ttname"><a href="structcoap__resource__t.html">coap_resource_t</a></div><div class="ttdef"><b>Definition</b> <a href="resource_8h_source.html#l00069">resource.h:69</a></div></div>
<div class="ttc" id="astructcoap__session__t_html"><div class="ttname"><a href="structcoap__session__t.html">coap_session_t</a></div><div class="ttdef"><b>Definition</b> <a href="coap__session_8h_source.html#l00056">coap_session.h:56</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="mem_8c.html">mem.c</a></li>
    <li class="footer">Generated on Fri Dec 27 2024 09:57:44 for libcoap by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8 </li>
  </ul>
</div>
</body>
</html>
